package com.example.zqm.git72.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zqm.git72.Activity.ClubDetailActivity;
import com.example.zqm.git72.Activity.MasterDetailActivity;
import com.example.zqm.git72.JavaBean.Activity;
import com.example.zqm.git72.JavaBean.Master;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import java.util.List;

//import com.example.zqm.git72.Activity.FoodActivity;

/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class MasterListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List<Master> mDataList;
    private LayoutInflater mLayoutInflater;
    //构造方法
    public MasterListAdapter(Context mContext, List<Master> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_master,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //把viewhoder数据映射到
        final Master entity = mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.master_name.setText(entity. getRealname());
        viewHolder.actcate_name.setText(entity. getActcate_name());
        if(entity.getThumb().equals("")){
            Picasso.with(mContext).load("https://b-ssl.duitang.com/uploads/item/201409/03/20140903102455_SNNnA.png"
            )
                    .resize(50,50).into(viewHolder.master_thumb);
        }else{
            String picUrl = "http://172.24.10.175/workout/Uploads/" + entity.getThumb();
            Picasso.with(mContext).load(picUrl.toString())
                    .resize(50,50).into(viewHolder.master_thumb);
        }
        //Context上下文在很多Android Api中都是必须的,图片网络加载地址,想进行图片展示的ImageView
        viewHolder.club_name.setText(entity.getClub_name());

        //iewHolder.news_keywords.setText(entity.getKeywords());
        //viewHolder.club_thumb.setImageResource(Integer.parseInt(entity.getThumb()));
         //viewHolder.news_star.setRating(Float.valueOf(entity.getLevel()));
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.putExtra("id",entity.getId());
                intent.setClass(mContext, MasterDetailActivity.class);
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView master_thumb;
        TextView master_name,actcate_name,club_name;
        //RatingBar news_star;
        //构造方法
        public ViewHolder(View itemView) {
            super(itemView);
            master_name = (TextView) itemView.findViewById(R.id.master_name);
            master_thumb = (ImageView) itemView.findViewById(R.id.master_thumb);
            actcate_name=(TextView) itemView.findViewById(R.id.actcate_name);
            club_name = (TextView) itemView.findViewById(R.id.club_name);
            //news_star =(RatingBar) itemView.findViewById(R.id. news_star);

        }
    }

}
